package logic

import (
	"context"
	"net/http"
	"strconv"
	"week1_zg6/orderapi/internal/svc"
	"week1_zg6/orderapi/internal/types"
	"week1_zg6/orderrpc/order"

	"github.com/zeromicro/go-zero/core/logx"
)

type HandlerNameLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewHandlerNameLogic(ctx context.Context, svcCtx *svc.ServiceContext) *HandlerNameLogic {
	return &HandlerNameLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *HandlerNameLogic) HandlerName(req *types.RenderTheOrderRequest) (resp *types.Response, err error) {
	pays, err := l.svcCtx.Order.RenderTheOrder(context.Background(), &order.RenderTheOrderRequest{
		OrderID: strconv.FormatInt(req.OrderID, 10),
	})
	if err != nil {
		return nil, err
	}
	return &types.Response{
		Code: http.StatusOK,
		Msg:  "",
		Date: map[string]interface{}{
			"OrderID":         pays.OrderID,
			"UserID":          pays.UserID,
			"OrderDate":       pays.OrderDate,
			"OrderStatus":     pays.OrderStatus,
			"ShippingAddress": pays.ShippingAddress,
			"TotalAmount":     pays.TotalAmount,
		},
	}, nil
}
